package cn.edu.ujn.project.supermarket.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.ujn.project.common.annotation.Log;
import cn.edu.ujn.project.common.core.controller.BaseController;
import cn.edu.ujn.project.common.core.domain.AjaxResult;
import cn.edu.ujn.project.common.core.page.TableDataInfo;
import cn.edu.ujn.project.common.enums.BusinessType;
import cn.edu.ujn.project.common.utils.poi.ExcelUtil;
import cn.edu.ujn.project.supermarket.domain.SellReport;
import cn.edu.ujn.project.supermarket.extendbean.SellReportChild;
import cn.edu.ujn.project.supermarket.service.IGoodsInforService;
import cn.edu.ujn.project.supermarket.service.ISellReportService;
import cn.edu.ujn.project.supermarket.service.IVipUserService;
import cn.edu.ujn.project.system.service.ISysUserService;

/**
 * 销售记录Controller
 * 
 * @author zhaomh
 * @date 2023-11-13
 */
@Controller
@RequestMapping("/system/sellreport")
public class SellReportController extends BaseController
{
    private String prefix = "system/sellreport";

    @Autowired
    private ISellReportService sellReportService;

    @Autowired
    private IVipUserService vipUserService;
    @Autowired
    private IGoodsInforService  goodsInforService;
    @Autowired
    private ISysUserService sysUserService;
    @RequiresPermissions("system:sellreport:view")
    @GetMapping()
    public String sellreport()
    {
        return prefix + "/sellreport";
    }

    /**
     * 查询销售记录列表
     */
    @RequiresPermissions("system:sellreport:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SellReportChild sellReport)
    {
        startPage();
        List<SellReportChild> list2 =sellReportService.selectSellReportChildList(sellReport);
        return getDataTable(list2);
    }

    /**
     * 导出销售记录列表
     */
    @RequiresPermissions("system:sellreport:export")
    @Log(title = "销售记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SellReportChild sellReport)
    {
    	 List<SellReportChild> list2 =sellReportService.selectSellReportChildList(sellReport);
        ExcelUtil<SellReportChild> util = new ExcelUtil<SellReportChild>(SellReportChild.class);
        return util.exportExcel(list2, "销售记录数据");
    }


    /**
     * 修改销售记录
     */
    @RequiresPermissions("system:sellreport:edit")
    @GetMapping("/edit/{sellId}")
    public String edit(@PathVariable("sellId") String sellId, ModelMap mmap)
    {
        SellReport sellReport = sellReportService.selectSellReportBySellId(sellId);
        mmap.put("sellReport", sellReport);
        return prefix + "/edit";
    }

    /**
     * 修改保存销售记录
     */
    @RequiresPermissions("system:sellreport:edit")
    @Log(title = "销售记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SellReport sellReport)
    {
        return toAjax(sellReportService.updateSellReport(sellReport));
    }

    /**
     * 删除销售记录
     */
    @RequiresPermissions("system:sellreport:remove")
    @Log(title = "销售记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sellReportService.deleteSellReportBySellIds(ids));
    }
}
